package arcturus;

import java.util.HashMap;

import mapProperties.EnemyEntity;
import mapProperties.Entity;

import org.omg.CORBA.UserException;

import acm.graphics.GImage;
import acm.graphics.GObject;
import acm.graphics.GRect;


public class Map extends HashVectorMapVer2<String, GObject>{
 	
	private AI gamePlayerAI;
	private Game g;
	public User theHuman;
	
	//====================================
	//====================================
	//====================================
	public Map(AI gamePlayerAI, Game g){
		this.gamePlayerAI = gamePlayerAI;
		this.g = g;
		this.theHuman = new User(User.USER_MAX_HEALTH, "freeman.png"); 

	}
	//====================================
	//====================================
	//====================================
	public void entityMoved(Entity e) throws Exception{
		System.out.println(e.toString());
		this.remove(String.valueOf(e.hashCode()));
		this.put(String.valueOf(e.hashCode()), e, (int)e.x, ((int)(e.x+e.getWidth())), (int)e.y, ((int)(e.y+e.getHeight())));
		this.g.remove(e);		
		this.g.add(e, e.x, e.y);					
	}
	//====================================
	//====================================
	//====================================
	
	
	
	//====================================
	//====================================
	//====================================
	public void loadMap(){
		
		
	}
	
	public boolean isCollidingNotWith(int movex, int movey, GObject value) {//too processor heavy
		boolean rval = false;
		GObject temp;
		for(int x = ((int)value.getX()); (!rval) && x <= (((int)value.getX()) + ((int) value.getWidth()) + movex); x++){
			for(int y = ((int)value.getY());(!rval) && y<= (((int)value.getY())+ ((int) value.getHeight()) + movey); y++){
				temp = this.getValueAt(x, y);
				rval = !value.equals(temp);
			}			
		}
		
		return rval;
	}
	//====================================
	//====================================
	//====================================
	
	public void loadMockup() throws Exception{			
		GRect groundStart = new GRect(g.getWidth(), 20);
		g.add(groundStart,0, g.getHeight() - groundStart.getHeight());
		
		this.put(String.valueOf(groundStart.hashCode()), (GObject)groundStart, 0,  (0+(int)groundStart.getWidth()), (g.getHeight() - (int)groundStart.getHeight()), g.getHeight());
		
		User freeman = this.theHuman;	
		this.theHuman.x=0;
		this.theHuman.y =  g.getHeight() + freeman.getHeight();
		
		EnemyEntity crab = new EnemyEntity("crab.png");	
		crab.x =g.getWidth()+200;
		crab.y = g.getHeight() + crab.getHeight() + 20 ;
		g.add(freeman, 0, g.getHeight() + freeman.getHeight());
		g.add(crab, g.getWidth()+200 ,g.getHeight() + crab.getHeight() + 20 );
		
		this.put(String.valueOf(freeman.hashCode()), freeman, 0, (0+(int)freeman.getWidth()),(g.getHeight() + (int)freeman.getHeight()),  (g.getHeight() + (int)freeman.getHeight()*2));
		
		this.put(String.valueOf(crab.hashCode()), crab,  (0+(int)crab.getWidth()),(g.getWidth()+200 + (int)crab.getWidth()),(g.getHeight() + (int)crab.getHeight()),  (g.getHeight() + (int)crab.getHeight()*2));
				
	}
}
